package com.zenithmind.library.pojo.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * 借阅统计视图对象
 * 
 * @author ZenithMind
 * @since 2024-06-14
 */
@Data
@Schema(name = "借阅统计视图对象", description = "借阅统计信息的视图对象")
public class BorrowStatisticsVO {

    @Schema(description = "统计日期")
    private LocalDate statisticsDate;

    @Schema(description = "总借阅次数")
    private Long totalBorrows;

    @Schema(description = "当前借阅数量")
    private Long currentBorrows;

    @Schema(description = "已归还数量")
    private Long returnedBorrows;

    @Schema(description = "逾期数量")
    private Long overdueBorrows;

    @Schema(description = "续借次数")
    private Long renewalCount;

    @Schema(description = "丢失数量")
    private Long lostBooks;

    @Schema(description = "损坏数量")
    private Long damagedBooks;

    @Schema(description = "总罚金金额")
    private BigDecimal totalFineAmount;

    @Schema(description = "已支付罚金")
    private BigDecimal paidFineAmount;

    @Schema(description = "未支付罚金")
    private BigDecimal unpaidFineAmount;

    @Schema(description = "活跃用户数")
    private Long activeUsers;

    @Schema(description = "新增用户数")
    private Long newUsers;

    @Schema(description = "热门图书数量")
    private Long popularBooks;

    @Schema(description = "平均借阅天数")
    private Double averageBorrowDays;

    @Schema(description = "图书利用率")
    private Double bookUtilizationRate;

    @Schema(description = "逾期率")
    private Double overdueRate;

    @Schema(description = "归还率")
    private Double returnRate;

    @Schema(description = "续借率")
    private Double renewalRate;

    @Schema(description = "用户满意度")
    private Double userSatisfaction;

    // 排行榜相关字段
    @Schema(description = "排名")
    private Integer ranking;

    @Schema(description = "图书ID")
    private String bookId;

    @Schema(description = "图书标题")
    private String bookTitle;

    @Schema(description = "用户ID")
    private String userId;

    @Schema(description = "用户姓名")
    private String userName;

    @Schema(description = "借阅次数")
    private Long borrowCount;

    @Schema(description = "评分")
    private BigDecimal rating;

    /**
     * 计算逾期率
     */
    public Double getOverdueRate() {
        if (totalBorrows == null || totalBorrows == 0) {
            return 0.0;
        }
        long overdue = overdueBorrows != null ? overdueBorrows : 0;
        return (double) overdue / totalBorrows * 100;
    }

    /**
     * 计算归还率
     */
    public Double getReturnRate() {
        if (totalBorrows == null || totalBorrows == 0) {
            return 0.0;
        }
        long returned = returnedBorrows != null ? returnedBorrows : 0;
        return (double) returned / totalBorrows * 100;
    }

    /**
     * 计算续借率
     */
    public Double getRenewalRate() {
        if (totalBorrows == null || totalBorrows == 0) {
            return 0.0;
        }
        long renewal = renewalCount != null ? renewalCount : 0;
        return (double) renewal / totalBorrows * 100;
    }

    /**
     * 计算图书利用率
     */
    public Double getBookUtilizationRate() {
        if (bookUtilizationRate != null) {
            return bookUtilizationRate;
        }
        // 这里需要根据具体业务逻辑计算
        return 0.0;
    }
}
